﻿namespace Sunny.Controls
{
	public class NumericExactValueSearchItem : SearchItem
	{
		private Telerik.Windows.Controls.RadNumericUpDown _SimpleSearcherInput;
		public override System.Windows.FrameworkElement SimpleSearcherInput
		{
			get
			{
				if (this._SimpleSearcherInput == null)
				{
					this._SimpleSearcherInput = new Telerik.Windows.Controls.RadNumericUpDown();
					this._SimpleSearcherInput.NumberFormatInfo = new System.Globalization.NumberFormatInfo() { NumberGroupSeparator = "" };
					this._SimpleSearcherInput.Value = null;
					this._SimpleSearcherInput.NumberDecimalDigits = 0;
				}
				return this._SimpleSearcherInput;
			}
		}

		public int NumberDecimalDigits
		{
			get
			{
				return ((Telerik.Windows.Controls.RadNumericUpDown)this.SimpleSearcherInput).NumberDecimalDigits;
			}
			set
			{
				((Telerik.Windows.Controls.RadNumericUpDown)this.SimpleSearcherInput).NumberDecimalDigits = value;
			}
		}

		public bool ShowButtons
		{
			get
			{
				return ((Telerik.Windows.Controls.RadNumericUpDown)this.SimpleSearcherInput).ShowButtons;
			}
			set
			{
				((Telerik.Windows.Controls.RadNumericUpDown)this.SimpleSearcherInput).ShowButtons = value;
			}
		}

		public double? Value
		{
			get
			{
				if (this._SimpleSearcherInput == null)
					return null;
				return this._SimpleSearcherInput.Value;
			}
			set
			{
				this._SimpleSearcherInput.Value = value;
			}
		}

		private Operator[] _OperatorOptions;
		public override Operator[] Operators
		{
			get
			{
				if (this._OperatorOptions == null)
					this._OperatorOptions = new Operator[]
					{
						new Operator(">","{0}>{1}"),
						new Operator("≥","{0}>={1}"),
						new Operator("<","{0}<{1}"),
						new Operator("≤","{0}<={1}"),
						new Operator("=","{0}={1}"),
						new Operator("≠","{0}!={1}")
					};
				return this._OperatorOptions;
			}
		}

		public override System.Windows.FrameworkElement AdvanceSearcherInput
		{
			get
			{
				return new Telerik.Windows.Controls.RadNumericUpDown();
			}
		}

		public override string InputValueProperty
		{
			get
			{
				return "Value";
			}
		}

		public override Searcher.WhereCommand GetCommand(string field, int index)
		{
			if (this._SimpleSearcherInput == null)
				return null;
			if (this._SimpleSearcherInput.Value== null)
				return null;
			return new Sunny.Controls.Searcher.WhereCommand { Text = string.Format("{0}==@{1}", field, index), Parameters = new object[] { (decimal?)this._SimpleSearcherInput.Value } };
		}

		public override void Empty()
		{
			if (this._SimpleSearcherInput != null)
				this._SimpleSearcherInput.Value = null;
		}
	}

	//public class DoubleExactValueSearchItem : SearchItem
	//{
	//	private Syncfusion.Windows.Shared.DoubleTextBox _SimpleSearcherInput;
	//	public override System.Windows.FrameworkElement SimpleSearcherInput
	//	{
	//		get
	//		{
	//			if (this._SimpleSearcherInput == null)
	//				this._SimpleSearcherInput = new Syncfusion.Windows.Shared.DoubleTextBox();
	//			return this._SimpleSearcherInput;
	//		}
	//	}

	//	public double? Value
	//	{
	//		get
	//		{
	//			if (this._SimpleSearcherInput == null)
	//				return null;
	//			return this._SimpleSearcherInput.Value;
	//		}
	//		set
	//		{
	//			this._SimpleSearcherInput.Value = value;
	//		}
	//	}

	//	/*
	//{ Text: "包含", Value: "{0}.Contains({1})" },
	//{ Text: "不包含", Value: "!{0}.Contains({1})" },
	//{ Text: "等于", Value: "{0}=={1}" },
	//{ Text: "始于", Value: "{0}.StartsWith({1})" },
	//{ Text: "非始于", Value: "!{0}.StartsWith({1})" },
	//{ Text: "终于", Value: "{0}.EndsWith({1})" },
	//{ Text: "非终于", Value: "!{0}.EndsWith({1})" }
	//	 */
	//	private Operator[] _OperatorOptions;
	//	public override Operator[] Operators
	//	{
	//		get
	//		{
	//			if (this._OperatorOptions == null)
	//				this._OperatorOptions = new Operator[]
	//				{
	//					new Operator(">","{0}>{1}"),
	//					new Operator("≥","{0}>={1}"),
	//					new Operator("<","{0}<{1}"),
	//					new Operator("≤","{0}<={1}"),
	//					new Operator("=","{0}={1}"),
	//					new Operator("≠","{0}!={1}")
	//				};
	//			return this._OperatorOptions;
	//		}
	//	}

	//	public override System.Windows.FrameworkElement AdvanceSearcherInput
	//	{
	//		get
	//		{
	//			return new Syncfusion.Windows.Shared.DoubleTextBox();
	//		}
	//	}

	//	public override string InputValueProperty
	//	{
	//		get
	//		{
	//			return "Value";
	//		}
	//	}

	//	public override Searcher.WhereCommand GetCommand(string field, int index)
	//	{
	//		if (this._SimpleSearcherInput == null)
	//			return null;
	//		if (string.IsNullOrEmpty(this._SimpleSearcherInput.Text))
	//			return null;
	//		return new Sunny.Controls.Searcher.WhereCommand { Text = string.Format("{0}==@{1}", field, index), Parameters = new object[] { this._SimpleSearcherInput.Value } };
	//	}

	//	public override void Empty()
	//	{
	//		if (this._SimpleSearcherInput != null)
	//			this._SimpleSearcherInput.Text = "";
	//	}
	//}
}